package com.future.direction.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.CacheUtils;
import com.future.direction.R;
import com.future.direction.common.util.PopuUtil;
import com.future.direction.common.util.UIUtil;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.widget.MyPopupWindow;
import com.future.direction.ui.widget.MyTitleBar;

import butterknife.BindView;

/**
 * Created by zhp on 2019-11-08
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.tv_setting_phone)
    TextView tvSettingPhone;
    @BindView(R.id.rl_setting_phone)
    RelativeLayout rlSettingPhone;
    @BindView(R.id.tv_setting_rom)
    TextView tvSettingRom;
    @BindView(R.id.rl_setting_clear)
    RelativeLayout rlSettingClear;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.button_logout)
    Button buttonLogout;


    @Override
    public int setLayout() {
        return R.layout.activity_setting;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        return false;
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        rlSettingPhone.setOnClickListener(this);
        rlSettingClear.setOnClickListener(this);
        buttonLogout.setOnClickListener(this);
        tvSettingPhone.setText("183xxxx5123");
        tvSettingRom.setText(CacheUtils.getInstance().getCacheSize() / 1024 / 1024 + "M");
    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_logout:
                //TODO 退出登录
                break;
            case R.id.rl_setting_phone:
                startActivity(new Intent(UIUtil.getContext(), BindPhoneActivity.class));
                break;
            case R.id.rl_setting_clear:
                if (CacheUtils.getInstance().getCacheSize() == 0) {
                    UIUtil.showLongToastSafe("暂时没有产生缓存");
                } else {
                    clearCache();
                }
                break;
        }
    }

    private void clearCache() {
        MyPopupWindow clearPopupWindow = new PopuUtil().initAtLocationPopuWrap(this,
                R.layout.popup_exit, llContent, 311, 126);
        TextView tvTitle = clearPopupWindow.getContentView().findViewById(R.id.tv_title);
        Button buttonPopupCancel = clearPopupWindow.getContentView().findViewById(R.id.button_creat_cancel);
        Button buttonPopupCommitSure = clearPopupWindow.getContentView().findViewById(R.id.button_creat_commit_sure);
        tvTitle.setText("确定清除缓存?");
        buttonPopupCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clearPopupWindow.dismiss();
            }
        });
        buttonPopupCommitSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CacheUtils.getInstance().clear();
                UIUtil.showLongToastSafe("缓存清除成功");
                clearPopupWindow.dismiss();
            }
        });
    }

}
